package com.seehack.sample.swagger.jaxrs;

import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.jaxrs.Reader;
import io.swagger.jaxrs.config.BeanConfig;
import io.swagger.jaxrs.config.DefaultReaderConfig;
import io.swagger.jaxrs.config.ReaderConfig;
import io.swagger.models.Swagger;
import io.swagger.util.Json;

import java.util.Collection;

public class BeanConfigGenerateSample {

    public static void main(String[] args) throws JsonProcessingException {
        /*
         * 通过扫描包获取swagger-bean
         */
        BeanConfig beanConfig = new BeanConfig();
        beanConfig.setResourcePackage("com.seehack.sample.swagger.jaxrs.api");
        DefaultReaderConfig readerConfig = new DefaultReaderConfig();
        readerConfig.setScanAllResources(true);
        Swagger swagger = new Reader(new Swagger(),readerConfig).read(beanConfig.classes());
        String json = Json.mapper().writerWithDefaultPrettyPrinter().writeValueAsString(swagger);
        System.out.println(json);
    }
}
